package cn.wbnyua.msm.web.service;

import cn.wbnyua.msm.core.exception.RuntimeExceptionHandler;
import cn.wbnyua.msm.util.JwtToken;
import cn.wbnyua.msm.web.dao.SysUserMapper;
import cn.wbnyua.msm.web.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 作者：wbnyua.
 * 创建时间: 2023/2/9 14:18.
 */

@Service
public class SysUserService {

    @Autowired
    private SysUserMapper mapper;

    public String login(SysUser user){
        SysUser dbUser = mapper.findByAccountAndPwd(user);
        System.out.println(dbUser);
        if (dbUser==null){
            throw new RuntimeExceptionHandler("用户名或密码错误");
        }
        if (!dbUser.isStatus()){
            throw new RuntimeExceptionHandler("账号异常，请联系管理员");
        }
        String token = JwtToken.makeToken(dbUser.getId(), 1);
        return token;
    }


}
